#!/usr/bin/perl
# CCNCore::IPC::Ticket
# Copyright (C) 2006, 2007  Stephane Alnet
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
# 

#
# For more information visit http://carrierclass.net/
#

package CCNCore::IPC::Ticket;
use strict; use warnings;
use base qw(CCN::IPC::Ticket);

use CCNCore::Home;
our $_directory = CCNCore::Home::config.'/local/spool/shared';
our $_name      = $_directory.'/ticket.sqlite3';
our $_dsn       = 'dbi:SQLite:dbname='.$_name;
our $_sql_file  = CCNCore::Home::manager.'/lib/CCN/IPC/ticket.sql';

sub create_db()
{
    my $self = shift;
    if( not -e $_name )
    {
        use CCNCore::Scripting;
        CCN::Scripting::exec_command(
            q(/usr/bin/sqlite3 ').$_name.q(' < ).$_sql_file
        );
    }

    use CCN::Database;
    return new CCN::Database($_dsn,'','');
}

sub submit_action($)
{
    my $self = shift;
    my $action = shift;

    use CCNCore::IPC::Spool;
    my $spool = new CCNCore::IPC::Spool;
    $spool->spool_request($action.' '.$self->ticket);
}

1;